<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增延期申请')" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-move-add">
        <div class="col-md-12">
            <div class="form-group">
                <label class="col-sm-3 control-label">申请延期的任务：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="tid" id="tid">
                        <option value="0">--请选择--</option>
                        <option th:each="info:${taskInfo}" th:value="${info.tid}" th:text="${info.target}"></option>
                    </select>
                </div>
            </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">申请人：</label>
                    <div class="col-sm-9">
                        <input name="" class="form-control" type="text" th:value="${user.userName}" disabled="disabled" />
                        <input name="alogname" type="hidden" th:value="${user.loginName}" />
                    </div>
                </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">移交人：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="ologname" id="ologname" >
                        <option value="">--请选择--</option>
                        <option th:each="u:${users}" th:text="${u.userName}" th:value="${u.loginName}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">转移原因：</label>
                <div class="col-sm-9">
                    <textarea type="text" name="reason" class="form-control" placeholder="请输入文本"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: ztree-js" />
<script type="text/javascript">
    var prefix = ctx + "cms/mm/move";

    $("#form-move-add").validate({
        required:true,
        onkeyup: false,
        rules:{
            tid:{
                remote: {
                    url: prefix + "/checkTidUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "tid": function() {
                            console.log($.common.trim($("#tid").val()));
                            return $.common.trim($("#tid").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            ologname:{
                remote: {
                    url: prefix + "/checkOlognameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "ologname": function() {
                            console.log($.common.trim($("#ologname").val()));
                            return $.common.trim($("#ologname").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "tid": {
                remote: "项目已经存在"
            },
            "ologname": {
                remote: "请重新选择"
            },
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            add();
        }
    }
    function add() {
        var vals = $("#form-move-add").serialize();
        $.ajax({
            cache : true,
            type : "POST",
            url : ctx + "cms/mm/move/add",
            data : vals,
            async : false,
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
                $.operate.successCallback(data);
            }
        });
    }
</script>
</body>
</html>